﻿using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using élénkPróbája.extentions;
using élénkPróbája.Test.extention;
using élénkPróbája.validators;

namespace élénkPróbája.Test
{
    [TestClass]
    public class DisplayAttrTester
    {
        public DisplayAttrTester()
        {
            CultureScope.SetDefaultCulture();
        }

        [TestMethod]
        public void Infers_display_name_from_DisplayAttribute()
        {
            var validator = new InlineValidator<DisplayNameTestModel> {
                v => v.RuleFor(x => x.Name1).NotNull()
            };

            var result = validator.Validate(new DisplayNameTestModel());
            result.Errors.Single().ErrorMessage.ShouldEqual("'Foo' should not be empty.");
        }
        [TestMethod]
        public void Infers_display_name_from_DisplayNameAttribute()
        {
            var validator = new InlineValidator<DisplayNameTestModel> {
                v => v.RuleFor(x => x.Name2).NotNull()
            };

            var result = validator.Validate(new DisplayNameTestModel());
            result.Errors.Single().ErrorMessage.ShouldEqual("'Bar' should not be empty.");
        }

        #region InternalClasses
        public class DisplayNameTestModel
        {
            [Display(Name = "Foo")]
            public string Name1 { get; set; }

#if !CoreCLR
            [DisplayName("Bar")]
#endif
            public string Name2 { get; set; }
        }
        #endregion
    }
}
